package freespiritsocial.io.user.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import freespiritsocial.io.user.R
import kotlinx.android.synthetic.main.activity_web.*
import me.hgj.jetpackmvvm.util.StatusBarUtil

class WebActivity: AppCompatActivity() {
    companion object {
        fun launch(context: Context,title: String,url: String) {
            context.startActivity(
                Intent(context,WebActivity::class.java).putExtra("title",title).putExtra("myurl",url)
            )
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_web)
        //设置状态栏透明
        StatusBarUtil.immersive(this)
        StatusBarUtil.darkMode(this)
        toolbar.setNavigationOnClickListener {
            finish()
        }
        tv_title.text = intent.getStringExtra("title")
        intent.getStringExtra("myurl").apply {
            webview.loadUrl(this ?: "")
        }
    }

    override fun onDestroy() {
        StatusBarUtil.darkMode(this,false)
        webview?.apply {
            (parent as ViewGroup).removeView(this)
            stopLoading()
            settings.javaScriptEnabled = false
            clearCache(true)
            clearHistory()
            clearView()
            removeAllViews()
            destroy()
        }
        super.onDestroy()

    }
}